﻿<?xml version="1.0" encoding="utf-8"?><Articles><Article><ArticlesID>547</ArticlesID><Title>Sự kh&amp;#225;c nhau giữa location.href vs location.replace</Title><Body>&amp;lt;p&amp;gt;Trong Javascript việc sử dụng c&amp;amp;acirc;u lệnh để Redirect người d&amp;amp;ugrave;ng kh&amp;amp;ocirc;ng phải l&amp;amp;agrave; điều qu&amp;amp;aacute; xa lạ.&amp;lt;/p&amp;gt;
&amp;lt;p&amp;gt;Để Redirect trong Javascript c&amp;amp;oacute; 2 c&amp;amp;aacute;ch:&amp;lt;/p&amp;gt;
&amp;lt;p&amp;gt;1. D&amp;amp;ugrave;ng location.href&amp;lt;/p&amp;gt;
&amp;lt;pre title=&amp;quot;code&amp;quot; class=&amp;quot;brush: jscript;&amp;quot;&amp;gt;
&amp;amp;lt;script type=&amp;amp;quot;text/javascript&amp;amp;quot;&amp;amp;gt;
location.href='http://dev.meotom.net';
&amp;amp;lt;/script&amp;amp;gt;&amp;lt;/pre&amp;gt;
&amp;lt;p&amp;gt;2. D&amp;amp;ugrave;ng location.replace(stringUrl)&amp;lt;/p&amp;gt;
&amp;lt;pre title=&amp;quot;code&amp;quot; class=&amp;quot;brush: jscript;&amp;quot;&amp;gt;
&amp;amp;lt;script type=&amp;amp;quot;text/javascript&amp;amp;quot;&amp;amp;gt;
location.replace('http://dev.meotom.net/');
&amp;amp;lt;/script&amp;amp;gt;&amp;lt;/pre&amp;gt;
&amp;lt;p&amp;gt;Vậy sự kh&amp;amp;aacute;c nhau giữa 2 c&amp;amp;aacute;ch n&amp;amp;agrave;y ở đ&amp;amp;acirc;u&amp;amp;nbsp;?&amp;lt;/p&amp;gt;
&amp;lt;p&amp;gt;Sử dụng location.href bạn sẽ lưu được history cho người d&amp;amp;ugrave;ng v&amp;amp;iacute; dụ t&amp;amp;ocirc;i đang ở trang A bạn redirect t&amp;amp;ocirc;i sang trang B&amp;amp;nbsp;d&amp;amp;ugrave;ng location.href sau đ&amp;amp;oacute; t&amp;amp;ocirc;i ấn n&amp;amp;uacute;t Back tr&amp;amp;ecirc;n tr&amp;amp;igrave;nh duyệt t&amp;amp;ocirc;i vẫn c&amp;amp;oacute; thể trở về trang A&amp;amp;nbsp;dễ d&amp;amp;agrave;ng nhưng đối với location.replace th&amp;amp;igrave; kh&amp;amp;ocirc;ng.&amp;lt;/p&amp;gt;</Body><CommentEnabled>True</CommentEnabled><ViewCount>0</ViewCount><ReleaseDate>10/26/2009 1:06:18 AM</ReleaseDate><TotalComment>0</TotalComment><IsMedia>False</IsMedia><IsPicture>False</IsPicture><IsVote>True</IsVote><ArticlePassword /><PostVisible>0</PostVisible><ArticlePath>/2009/10/26/Su-kh-225c-nhau-giua-locationhref-vs-locationreplace-223</ArticlePath><Approved>True</Approved><ImagePath /><CategoryId>30</CategoryId><ArrayCatID>30|25</ArrayCatID></Article></Articles>